<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Baibao_model extends CI_Model {
	public $table = 'baibao';

	function save($data, $user_id){
		if($this->deleteAllByUser($user_id)){
			if(!$data) return true;
			return $this->db->insert_batch($this->table, $data);
		}
		return false;
	}
	
	function getAllByUserId($user_id){
		$query = $this->db->select('*')->from($this->table)->where('user_id', $user_id)->get();
		return $query->result();
	}
	
	function deleteAllByUser($user_id){
		return $this->db->delete($this->table, array('user_id' => $user_id));
	}
}